#include <iostream>
#include <vector>

using namespace std;
class Subject;
class Observer;
class Subject{
public:
    virtual void Add(Observer * observer)=0;
    virtual void notify(int,int)=0;
};

class Observer{
protected:
    Subject * subject;
public:
    Observer(){}
    Observer(Subject * s){
        this->subject = s;
        subject->Add(this);
    }
    virtual void update(int ,int )=0;
};
class ConcreateObserverA:public Observer{
private:
    int x,y;
public:
    ConcreateObserverA(Subject * t):Observer(t){}
    void update(int x,int y){
        this->x = x;
        this->y = y;
        cout<<x<<y<<endl;
    }
};

class ConcreateSubjectA:public Subject{
private:
    int x,y;
    vector<Observer *> vec;
public:
    ConcreateSubjectA(){
        x=0;
        y=0;
    }
    ConcreateSubjectA(int x,int y){
        this->x = x;
        this->y = y;
    }
    void Add(Observer * observer){
        vec.push_back(observer);
    }
    void notify(int x,int y){
        vector<Observer *>::iterator it;
        for(it = vec.begin();it != vec.end();it++)
            (*it)->update(x,y);
    }
    void DataChange(int x,int y){
        this->x = x;
        this->y = y;
        notify(x,y);
    }
};
int main() {
    ConcreateSubjectA * concreateSubjectA= new ConcreateSubjectA();
    ConcreateObserverA * concreateObserverA = new ConcreateObserverA(concreateSubjectA);
    concreateSubjectA->DataChange(3,5);
}